#!/bin/sh

# Purpose : Testing script for dpkg support
# Author  : Ky-Anh Huynh
# License : MIT

# FIXME: debian:squeeze It's unable to run `pacman -Sy`
im ubuntu:14.04 ubuntu:16.04  ubuntu:18.04   ubuntu:20.04  ubuntu
im              debian:jessie debian:stretch debian:buster debian:bullseye
im debian_bash3

# Remove `docker-clean` because we need *.deb files under /var/cache
in ! rm -fv /etc/apt/apt.conf.d/docker-clean
ou ^removed .*docker-clean

in ! PACAPT_DEBUG=auto pacman
in ! if bash --version | grep -qs 'version 3'; then echo "Bash3-no-switching"; fi
ou (debug.*Switching to Bash shell)|(Bash3-no-switching)

in -P
ou available operations:.*( [Q][ ilos])+

# Update package databases
in -Sy
ou ^Get
ou ^Fetched
in -Sy --quiet --quiet
ou empty
in -Sy -qq
ou empty

# Simple query that lists all packages
in -Qq
ou ^apt$

# Listing with version and package name
in -Q
# ou ^ii +apt +.+ubuntu
ou ^ii +apt +

# List explicitly installed packages
in ! if [ "$(cat /etc/*-release | grep -E ^VERSION_CODENAME= | cut -d'=' -f2)" = "bullseye" ]; then pacman -S --noconfirm iproute2; fi
in -Qe
ou ^(iproute2|adduser)$

# Information of `apt`
in -Qi apt
ou ^Package: apt$
ou ^Status: install ok installed$
ou ^Priority: (important|required)$

# File listing for `apt`
in -Ql apt
ou ^/usr/bin/apt-key

# File listing (all packages)
# FIXME: Debian-squeeze doesn't have /usr/bin/apt
in -Ql
ou ^apt /usr/bin/apt-key$

# File listing (all packages), files only
in -Qql
ou ^/usr/bin/apt-key$

# Look up package name
in -Qo /bin/bash
ou ^bash: /bin/bash$

# On ubuntu:20.04, /usr/bin/bash is not part of the `bash` package
# (maybe it's a symlink/file created by installation process)
# hence the looking up would fail
in -Qo bash
ou ^bash: /bin/bash$

# Search for pattern in installed package (names + descriptions)
in -Qs bash
ou ^bash.+Bourne

in -Qs bourne
ou ^bash.+Bourne

in -Qs screen
ou empty

in -Qs 'Bourne Again'
ou ^bash.+Bourne

# Install and Deinstall a package

# Download without installation
in -Sw --noconfirm screen
in ! command -v screen || echo 'command not found'
ou command not found

# Display remote package information
in -Si screen
ou ^Package: screen

in -Sii screen
ou ^Reverse Depends:

# Get package changelog
in -Qc apt
ou ^(Get|Err).+ apt

# Now installation
# From ubuntu:20.04 it becomes /bin/screen =))
in -S --noconfirm screen
in ! command -v screen
ou ^(/usr)?/bin/screen

# Now remove the package
in -R --noconfirm screen
in -Qi screen
ou ^Status: deinstall

# Verify package files
in -Qk apt
ou requires 'debsums' but the tool is not found\.$
in -S --noconfirm debsums
in -Qk apt
ou /usr/bin/apt.+OK
ou /usr/bin/apt-get.+OK
in -Qk
ou /usr/bin/apt.+OK
in -R --noconfirm debsums

# Package groups
in -Sg
ou requires 'tasksel' but the tool is not found\.$
in -S --noconfirm tasksel
in -Sg
# debian*?                          -> web-server
# ubuntu(:(18.04|20.04))?           -> ubuntu-desktop
# ubuntu:(14.04|16.04)              -> manual
ou ^u (web-server|ubuntu-desktop|manual)

in ! if [ "$(cat /etc/*-release | grep -E ^ID= | cut -d'=' -f2)" = "ubuntu" ]; then pacman -Sg ubuntu-desktop; else pacman -Sg web-server; fi
ou ^(task-web-server|ubuntu-desktop)
in -R --noconfirm tasksel

# Query information from a .deb package
in ! export DEB_FILE=`find /var/cache/apt/ -type f -iname "screen*.deb"`
in -Qp $DEB_FILE
ou ^ Package: screen

# Clean up package databases
in -Sc
in clear
in -sS tmux
ou package/tmux
ou terminal multiplexer

# Strong cleaning up
in -Sccc
in clear
in -sS tmux
ou empty
